<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>模块管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../lib/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../css/x-admin.css" media="all">
		<script src="../js/global.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" href="layui/css/layui.css">
  		 <script src="layui/layui.js" charset="utf-8"></script>
	</head>

	<body>
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
			<legend>系統功能模块维护</legend>
		</fieldset>
		<div class="layui-container">
			<div class="layui-row">
				<div class="layui-col-md3">
					<div id="test1" class="demo-tree demo-tree-box"></div>
				</div>
				<div class="layui-col-md9">
					<div id="divModuleB">
						<button id="btnAddChild" type="button" class="layui-btn layui-btn-sm">添加子节点</button>
						<button id="btnChangeParent" type="button" class="layui-btn layui-btn-normal layui-btn-sm">设置父节点</button>
						<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
							<legend><span id="spTitle">功能模块信息维护</span></legend>
						</fieldset>
						<form id="formSave" class="layui-form" action="">
							<div class="layui-form-item">
								<label class="layui-form-label">父节点编号</label>
								<div class="layui-input-block">
									<input id="txtParentId" type="text" disabled="disabled" value="0" class="layui-input">
									<input id="hfParentId" type="hidden" name="parentId">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">节点编号</label>
								<div class="layui-input-block">
									<input id="hfId" type="hidden" name="mId">
									<input id="txtId" type="text" disabled="disabled" value="0" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">节点名称</label>
								<div class="layui-input-block">
									<input id="txtName" type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入节点名称" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">路径</label>
								<div class="layui-input-block">
									<input id="txtPath" type="text" name="path" placeholder="请输入功能路径" autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label">权重</label>
								<div class="layui-input-block">
									<input id="txtWeight" type="text" name="weight" lay-verify="required|number" placeholder="请输入权重(整数)" autocomplete="off" class="layui-input">
								</div>
							</div>

							<div class="layui-form-item">
								<div class="layui-input-block">
									<button class="layui-btn" lay-submit="" lay-filter="subData">保存</button>
									<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
<script>
	var treeMethod = {
		add: function(obj) {

		},
		update: function(obj) {
			
		},
		del: function(obj) {
			
		}
	}
</script>

		<script>
		layui.use(['tree', 'util'], function(){
			  var tree = layui.tree
			  ,layer = layui.layer
			  ,util = layui.util
			  //模拟数据1
			  ,data = [{
			    title: '江西'
			    ,id: 1
			    ,children: [{
			      title: '南昌'
			      ,id: 1000
			      ,children: [{
			        title: '青山湖区'
			        ,id: 10001
			      },{
			        title: '高新区'
			        ,id: 10002
			      }]
			    },{
			      title: '九江'
			      ,id: 1001
			    },{
			      title: '赣州'
			      ,id: 1002
			    }]
			  },{
			    title: '广西'
			    ,id: 2
			    ,children: [{
			      title: '南宁'
			      ,id: 2000
			    },{
			      title: '桂林'
			      ,id: 2001
			    }]
			  },{
			    title: '陕西'
			    ,id: 3
			    ,children: [{
			      title: '西安'
			      ,id: 3000
			    },{
			      title: '延安'
			      ,id: 3001
			    }]
			  }]
			  //常规用法
			  tree.render({
			    elem: '#test1',//默认是点击节点可进行收缩
			    data: data,
			  });
			});
					
					
				/* 	 //添加子节点操作
					if($("#hfId").val() == "0") {
						var str = $("#formSave").serialize() + "&token=" + globalData.myToken;
						$.post(globalData.server + "CreateModule", str, function(res) {
							if(res.success) {
								layer.msg("添加成功");
								active["reload"].call(null);
							} else
								layer.msg("添加失败：" + res.message);
							layer.close(ix);
						}, "json");
					} else { //更新节点或调整父节点
						$("#hfParentId").val($("#txtParentId").val());
						var title = $("#txtName").val();
						var str = $("#formSave").serialize() + "&token=" + globalData.myToken;
						$.post(globalData.server + "UpdateModule", str, function(res) {
							if(res.success) {
								layer.msg("保存成功");
								$("#txtParentId").attr("disabled", "disabled");
								$("#txtId").attr("disabled", "disabled");
								treeNode.data.title = title;
								treeNode.elem.find('.layui-tree-txt').html(title);
							} else
								layer.msg("保存失败：" + res.message);
							layer.close(ix);
						}, "json");
					}
					return false;
				});
				$(function() {
					$("#btnAddChild").click(function() {
						var id = $("#hfId").val();
						var name = $("#txtName").val();
						$("#spTitle").html("为【" + name + "】添加子节点");
						$("#hfId").val("0");
						$("#txtId").val("0");
						$("#hfParentId").val(id);
						$("#txtParentId").val(id);
						$("#txtName").val("");
						$("#txtPath").val("");
						$("#txtWeight").val("");
					});
					$("#btnChangeParent").click(function() {
						var id = $("#hfId").val();
						var name = $("#txtName").val();
						$("#spTitle").html("为【" + name + "】调整父编号");
						$("#txtParentId").removeAttr("disabled");
					});
				})
				active = {
					reload: function() {
						$.post(globalData.server + "GetAllModuleLayUI", {
							"token": globalData.myToken
						}, function(res) {
							tree.reload('tv', {
								data: res
							});
						}, "json");
					},
					load: function() { //加载当前页
						$.post(globalData.server + "GetAllModuleLayUI", {
							"token": globalData.myToken
						}, function(res) {
							tree.render({
								id: "tv",
								elem: "#divModules",
								data: res,
								edit: ['del'],
								operate: function(obj) {

								},
								click: function(obj) {
									$("#spTitle").html("功能模块信息维护");
									treeNode = obj;
									var index = layer.load(0, {
										shade: false
									});
									$.post(globalData.server + "GetModuleById", {
										"token": globalData.myToken,
										"id": obj.data.id
									}, function(res) {
										if(res.success) {
											var d = JSON.parse(res.message);
											$("#txtId").val(d.id)
											$("#hfId").val(d.id);
											$("#txtParentId").val(d.parentId);
											$("#hfParentId").val(d.parentId);
											$("#txtName").val(d.name);
											$("#txtPath").val(d.url);
											$("#txtWeight").val(d.weight);
										} else {
											layer.msg("操作失败：" + res.message);
										}
										layer.close(index);
									}, "json")
								}
							});
						}, "json");
					}
				};
				active["load"].call(null);
			});  */
		</script>

	</body>

</html>